import mixins from '../mixins';
Component({
  mixins: [mixins],
  data: {
    show: true,
    onChangeFunc: null,
    currIndex: 0,
  },
  props: {},
  didMount() {
    this.setData({
      item: this.props.data,
    })
  },
  methods: {
    onSwiperChange(func) {
      this.setData({
        onChangeFunc: func
      })
    },
    onChange(e) {
      this.setData({
        currIndex: e.detail.current
      })
      try {
        this.data.onChangeFunc(e.detail.current)
      } catch (e) {

      }
    },
    changeTo(_index) {
      this.onChange({ detail: { current: _index } })
    },
    toNext() {
      this.navigationRight();
    },
    toPrev() {
      this.navigationLeft()
    },
    navigationRight() {
      let { currIndex } = this.data;
      let index = currIndex < (this.data.item.children.length - 1) ? currIndex + 1 : 0;
      this.changeTo(index)
    },
    navigationLeft() {
      let { currIndex } = this.data;
      let index = currIndex > 0 ? currIndex - 1 : this.data.item.children.length - 1;
      this.changeTo(index)
    }
  },
});
